import unittest,requests

from Daywu.yuekao.excel import excel
excelpath="D:\python pojects\Daywu\yuekao\yk.xlsx"
sheetname="Sheet1"
dy=excel(excelpath,sheetname)

# 数据驱动
from ddt import ddt,file_data,data,unpack
@ddt
class MyTestCase(unittest.TestCase):
    host='http://10.59.9.18'
    userId=None
    sessionId=None
    # 登录
    # @data(*dy.getdata())
    # @unpack
    # def test_01_login(self,phone,pwd):
    #     url=MyTestCase.host+'/small/user/v1/login'
    #     json={"phone":phone,"pwd":pwd}
    #     r_login=requests.post(url=url,json=json)
    #     print(r_login.json())
    #     MyTestCase.userId=str(r_login.json()['result']['userId'])
    #     MyTestCase.sessionId = r_login.json()['result']['sessionId']
    #     self.assertEqual(MyTestCase.userId, '30498')

    # 登录
    @file_data('day.json')
    def test_01_login(self,phone,pwd,title,yuqi):
        url=MyTestCase.host+'/small/user/v1/login'
        json={"phone":phone,"pwd":pwd}
        r_login=requests.post(url=url,json=json)
        print(r_login.json())
        if title==1:
            MyTestCase.userId=str(r_login.json()['result']['userId'])
            MyTestCase.sessionId = r_login.json()['result']['sessionId']
            self.assertEqual(MyTestCase.userId, '30498')
        else:
            self.assertEqual(yuqi, '登录失败')

    #圈子列表
    commodityId=None
    def test_02_list(self):
        url=MyTestCase.host+'/small/circle/v1/findCircleList'
        headers={"userId":MyTestCase.userId,"sessionId":MyTestCase.sessionId}
        json={"page":"1","count":"5"}
        r_list=requests.get(url=url,params=json,headers=headers)
        print(r_list.json())
        MyTestCase.commodityId=str(r_list.json()['result'][0]['commodityId'])
        self.assertIn(MyTestCase.commodityId,'12')
    #发布圈子
    def test_03_release(self):
        url=MyTestCase.host+'/small/circle/verify/v1/releaseCircle'
        headers={"userId":MyTestCase.userId,"sessionId":MyTestCase.sessionId}
        json={"commodityId":MyTestCase.commodityId,"content":"给大家推荐一个好商品","image":"1.png"}
        r_release=requests.post(url=url,data=json,headers=headers)
        print(r_release.json())
        MyTestCase.commodityId=r_release.json()['status']
        self.assertTrue(MyTestCase.commodityId,'500')
    # 删除圈子
    def test_04_delete(self):
        url = MyTestCase.host + '/small/circle/verify/v1/deleteCircle'
        headers = {"userId": MyTestCase.userId, "sessionId": MyTestCase.sessionId}
        json = {"circleId":"1,2,4"}
        r_delete = requests.delete(url=url, data=json, headers=headers)
        print(r_delete.json())
        MyTestCase.message = r_delete.json()['message']
        self.assertNotEqual(MyTestCase.message, '1')

if __name__ == '__main__':
    unittest.main()
